<template>
  <ul v-if="list?.length">
    <li v-for="(item, index) in list" :key="'menu' + index" :class="[currentRoute.split('_')[0] === item.value ? 'actived' : '']">
      <a v-if="item.link.indexOf('/') < 0" :href="item.link">{{ item.text }}</a>
      <span v-else @click.stop="handledMenu(item)">{{ item.text }}</span>
      <chidMenu v-if="currentRoute.split('_')[0] === item.value" :list="item.child" />
    </li>
  </ul>
</template>

<script>
export default {
  name: "chidMenu",
  props: {
    list: {
      required: true,
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {}
  },
  computed: {
    currentRoute() {
      return this.$store.state.currentRoute || ""
    },
  },
  created() {},
  methods: {
    handledMenu(menu) {
      this.$router.push({
        path: menu.link,
      })
    },
  },
}
</script>
<style lang="less" scoped>
li {
  display: inline-block;
  position: relative;
  cursor: pointer;
  text-align: center;
  &:hover {
    ul {
      max-height: 100rem;
    }
  }
  a,
  span {
    display: block;
    padding: @normal @normal;
    min-width: 8rem;
    font-size: 1.08rem;
    color: @basicColor;
    transition: all 0.3s;
  }
  span:hover,
  a:hover {
    transform: scale(1.2);
  }

  & > ul {
    overflow: hidden;
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    max-height: 0;
    background-color: @headerBgColor;
    transition: max-height 0.3s ease-out;

    li {
      display: block;
      transition: all 0.6s;
    }
  }
}
</style>
